<?php


class keke_shop_class {

	public static function get_service_info($service_id)
	{
		$service_obj=new Keke_witkey_service_class();
		$service_obj->setWhere ( "service_id = '$service_id'" );
        $service_info = $service_obj->query_keke_witkey_service ();
        $service_arr = $service_info [0];
        return $service_arr;
		
	}

	public static function get_shop_info($shop_id)
	{
	$shop_info = db_factory::query ( "select b.*,a.* from " . TABLEPRE . "witkey_shop a left join " . TABLEPRE . "witkey_space b on a.uid = b.uid where a.shop_id = '$shop_id'" );
    $shop_info = $shop_info [0];
    return $shop_info;
		
	}

	 static function get_shop_logo($shop_id)
	{
	$shop_logo = db_factory::query ( "select shop_logo from " . TABLEPRE . "witkey_shop_tpl_econfig where shop_id = '$shop_id'" );
    $shop_logo = $shop_logo [0] ['shop_logo'];
    return $shop_logo;
		
	}

	static function create_order($buy_uid,$buy_username,$sale_uid,$sale_username,$price,$title,$service_id,$sercice_type,$shop_id)
	{
		  $service_order_obj=new Keke_witkey_service_order_class();
	        $service_order_obj->_order_id = null;
			$service_order_obj->setBuy_uid ( $buy_uid );
			$service_order_obj->setBuy_username ( $buy_username );
			$service_order_obj->setOn_time ( time () );
			if($sercice_type==2)
			{
			$service_order_obj->setOrder_status ( 2 );
			}
			elseif($sercice_type==1)
			{
			$service_order_obj->setOrder_status ( 0 );
			}
			$service_order_obj->setCount_cash($price);
			$service_order_obj->setTitle($title);
			$service_order_obj->setSale_uid ( $sale_uid );
			$service_order_obj->setSale_username ( $sale_username );
			$service_order_obj->setService_id ( $service_id );
			$service_order_obj->setService_type ($sercice_type );
			$service_order_obj->setShop_id ( $shop_id );
	        if($sercice_type==2)
			{
			$service_order_obj->setBuyer_status ( 1 );
			}
			elseif($sercice_type==1)
			{
			$service_order_obj->setBuyer_status ( 0 );
			}
			$service_order_obj->setSale_status ( 0 );
			$order_id = $service_order_obj->create_keke_witkey_service_order ();
			return $order_id;
		
	}

	static function create_new_step($new_detail_arr,$order_id)
	{
		$order_detail_obj = new Keke_witkey_service_order_detail_class ();
	    foreach ( $new_detail_arr as  $k => $detail ) {
	    	
				$order_detail_obj->_detail_id = null;
				$order_detail_obj->setStep_cash ( $detail ['step_cash'] );
				$order_detail_obj->setStep_detail ( $detail ['step_detail'] );
				$order_detail_obj->setStep_num ( $k );
				$order_detail_obj->setStep_status ( 0 );
				$order_detail_obj->setOrder_id ( $order_id );
				$res+=$order_detail_obj->create_keke_witkey_service_order_detail ();
	    }
	    return $res;
		
	}
  
	static function delete_detail_step($detail_arr)
	{
		$order_detail_obj = new Keke_witkey_service_order_detail_class ();
	   $order_detail_obj->setWhere ( "detail_id in ($detail_arr[del])" );
		$res = $order_detail_obj->del_keke_witkey_service_order_detail ();
	    return $res;
	}
	
	static function update_order_status($order_id,$status)
	{
		$service_order_obj=new Keke_witkey_service_order_class();
		$service_order_obj->setWhere ( "order_id = '$order_id'" );
		$service_order_obj->setOrder_status ( $status );
		$res=$service_order_obj->edit_keke_witkey_service_order ();
		return $res;
		
	}

	static function update_custom_status($order_id,$step,$is_saler=1)
	{
		$service_order_obj = new Keke_witkey_service_order_class();
		$service_order_obj->setWhere ( "order_id = '$order_id'" );
		if($is_saler)
		{
		$service_order_obj->setSale_status ( intval ( $step ) );
		}
		else 
		{
		$service_order_obj->setBuyer_status ( intval ( $step ) );
		}
		$service_order_obj->edit_keke_witkey_service_order ();
		return $res;
		
	}

	 static function insert_into_file($obj_type,$obj_id,$file_name,$save_name,$uid,$username)
	{
		$file_obj=new Keke_witkey_file_class();
		$file_obj->_file_id = null;
		$file_obj->setObj_type ( $obj_type );
		$file_obj->setObj_id ( $obj_id );
		$file_obj->setFile_name ( $file_name );
		$file_obj->setFile_save_name ( "data/uploads/" . UPLOAD_RULE . $save_name );
		$file_obj->setUid ( $uid );
		$file_obj->setUsername ( $username );
		$file_obj->setOn_time ( time () );
		$res=$file_obj->create_keke_witkey_file ();
		return $res;
		
	}

	static function get_order_file($order_id)
	{
		$file_obj = new Keke_witkey_file_class ();
		$file_obj->setWhere ( "obj_type = 'service_order' and obj_id = " . intval ( $order_id ) );
		$file_list = $file_obj->query_keke_witkey_file ();
		return $file_list;
		
	}

 static function is_shop_order($service_id,$order_id,$uid=null)
	{
	$service_id=intval($service_id);
	if($uid)
	{
		$sql=" select a.*,b.file_path,b.submit_method from ".TABLEPRE."witkey_service_order as a left join ".TABLEPRE."witkey_service as b on a.service_id= b.service_id where a.service_id ='$service_id' and a.buy_uid = '$uid' order by a.on_time desc limit 0,1 ";
	}
	else 
	{
		$sql=" select a.*,b.file_path,b.submit_method from ".TABLEPRE."witkey_service_order as a left join ".TABLEPRE."witkey_service as b on a.service_id= b.service_id where a.service_id ='$service_id' and a.order_id = '$order_id' order by a.on_time desc limit 0,1 ";
	} 
	$order_info = db_factory::query($sql);
	$order_info = $order_info [0];
    return $order_info;
		
	}
}
?>